// Tierless
// Copyright © 2010 Alphora
// This file is licensed under a modified BSD-license (see tierless_license.txt).
using System.Collections.Generic;

namespace Tierless.Framework.EntityTypes
{
	/// <summary>
	/// Represents a collection of <see cref="EntityTypeColumnReference"/> instances.
	/// </summary>
	public class EntityTypeColumnReferenceCollection : NamedEntityObjectTypeCollection<EntityTypeColumnReference>
	{
		/// <summary>
		/// Initializes a new instance of the EntityTypeColumnReferenceCollection class.
		/// </summary>
		public EntityTypeColumnReferenceCollection()
		{}

		/// <summary>
		/// Initializes a new instance of the EntityTypeColumnReferenceCollection class.
		/// </summary>
		/// <param name="columnNames">The names of the referenced columns.</param>
		public EntityTypeColumnReferenceCollection(IEnumerable<string> columnNames)
		{
			foreach (var name in columnNames)
				Add(new EntityTypeColumnReference(name));
		}

		/// <summary>
		/// Gets or sets the collection as an array of strings.
		/// </summary>
		public string[] AsStringArray
		{
			get
			{
				var result = new string[Count];
				for (var i = 0; i < Count; i++)
					result[i] = this[i].Name;
				return result;
			}
			set
			{
				Clear();
				foreach (var name in value)
					Add(new EntityTypeColumnReference(name));
			}
		}
	}
}